package ro.myApp.security.entities;

import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

import org.hibernate.validator.Email;
import org.hibernate.validator.NotEmpty;

import ro.myApp.commons.basic.PersistentEntity;
import ro.myApp.security.util.RoleEnum;

/**
 * @author anamaria
 * @version 1.0
 * @created 20-feb.-2010 01:12:15
 */

@Entity
@Table(name = "CUSTOM_USER", uniqueConstraints = { @UniqueConstraint(columnNames = { "username" }) })
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "USER_TYPE")
@DiscriminatorValue("USR")
public class User extends PersistentEntity {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@NotEmpty
	@Column(nullable = false)
	private String firstName;

	@NotEmpty
	@Column(nullable = false)
	private String lastName;

	@NotEmpty
	@Column(nullable = false)
	private String username;

	@NotEmpty
	@Column(nullable = false)
	private String password;
	
	private boolean active;

	@NotEmpty
	@Email
	@Column(nullable = false)
	private String emailAddress;
	
	private String address;
	

	@NotEmpty
	@Column(nullable = false)
	private String afiliation;
	
	private int age;
	
	private String interests;

	@OneToOne(fetch = FetchType.LAZY)
	private Role role;

	public User() {
	}

	public User(Long id, Integer version, boolean deleted, String code,
			String label, String description, String createdByUsername,
			String updatedByUsername, Date dateCreated, Date dateUpdated,
			String type, String firstName, String lastName, String username,
			String password, String emailAddress, Role role) {

		super(id, version, deleted, code, label, description,
				createdByUsername, updatedByUsername, dateCreated, dateUpdated,
				type);

		this.firstName = firstName;
		this.lastName = lastName;
		this.username = username;
		this.password = password;
		this.emailAddress = emailAddress;
		this.role = role;
	}

	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public Role getRole() {
		return role;
	}

	public void setRole(Role role) {
		this.role = role;
	}

	public String getEmailAddress() {
		return emailAddress;
	}

	public void setEmailAddress(String emailAddress) {
		this.emailAddress = emailAddress;
	}
	
	public boolean isActive() {
		return active;
	}
	
	public void setActive(boolean active) {
		this.active = active;
	}

	public String getAddress() {
		return address;
	}
	
	public void setAddress(String address) {
		this.address = address;
	}
	
	public String getAfiliation() {
		return afiliation;
	}
	
	public void setAfiliation(String afiliation) {
		this.afiliation = afiliation;
	}
	
	public int getAge() {
		return age;
	}
	
	public void setAge(int age) {
		this.age = age;
	}
	
	public String getInterests() {
		return interests;
	}
	public void setInterests(String interests) {
		this.interests = interests;
	}

	@Override
	public String toString() {
		return "User [firstName=" + firstName + ", lastName=" + lastName
				+ ", username=" + username + ", password=" + password
				+ ", emailAddress=" + emailAddress + "]";
	}

}